/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmVector.java
 *
 * Created on 04-dic-2014, 10:24:20
 */
package presentacion;

/**
 *
 * @author sistemas
 */
import javax.swing.table.DefaultTableModel;
import Negocio.Entero;
import Negocio.VectorEntero;
public class FrmVector extends javax.swing.JFrame {

    /** Creates new form FrmVector */
    public FrmVector() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtDimension = new javax.swing.JTextField();
        btnDimensionar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        btnOrdenar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Dimesion");

        btnDimensionar.setText("Dimensionar");
        btnDimensionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDimensionarActionPerformed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable1.setToolTipText("DefaultTableModel");
        jScrollPane2.setViewportView(jTable1);

        btnOrdenar.setText("Ordenar");
        btnOrdenar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOrdenarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(83, 83, 83)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtDimension, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addComponent(btnDimensionar)
                .addContainerGap(79, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnOrdenar)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(48, 48, 48))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(btnDimensionar)
                    .addComponent(txtDimension, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(btnOrdenar)
                .addContainerGap(122, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void Dimensionar(int CantidadColumna){
        DefaultTableModel modelo=new DefaultTableModel();
        this.jTable1.setModel(modelo);
        for(int i=0;i<=CantidadColumna-1;i++){
            modelo.addColumn(Integer.toString(i));
        }
        Object[] fila=new Object[1];
        modelo.addRow(fila);
    }
    private void btnDimensionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDimensionarActionPerformed
        // TODO add your handling code here:
        this.Dimensionar(Integer.parseInt(this.txtDimension.getText()));
    }//GEN-LAST:event_btnDimensionarActionPerformed

    private void CargarVector(Negocio.VectorEntero ObjVector){
        for(int i=0;i<=Integer.parseInt(this.txtDimension.getText())-1;i++){
            Entero objEntero=new Entero();
            objEntero.setNum(Integer.parseInt(jTable1.getValueAt(0, i).toString()));
            ObjVector.Insertar(objEntero);
        }
    }
    private void MostrarVector(Negocio.VectorEntero ObjVector){
        this.Dimensionar(ObjVector.getN());
        for(int i=0;i<=ObjVector.getN()-1;i++){
            jTable1.setValueAt(ObjVector.LeerVetor(i).getNum(), 0, i);
        }
    }
    private void btnOrdenarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOrdenarActionPerformed
        // TODO add your handling code here:
        Negocio.VectorEntero objVector=new VectorEntero();
        this.CargarVector(objVector);
        objVector.Ordenar();
        this.MostrarVector(objVector);
    }//GEN-LAST:event_btnOrdenarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FrmVector().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDimensionar;
    private javax.swing.JButton btnOrdenar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField txtDimension;
    // End of variables declaration//GEN-END:variables
}
